package com.longqinuo.mycarservice.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by zxw on 2016/6/8.
 */
public class IndexBarAdapter extends BaseAdapter {
    private Context ct;
    private List<String> chs;
    private int height;


    public IndexBarAdapter(Context ct, List<String> chs, int height) {
        super();
        this.ct = ct;
        this.chs = chs;
        this.height = height;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return chs.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return chs.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            AbsListView.LayoutParams params = new  AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, height/chs.size());
            TextView tv = new TextView(ct);
            tv.setLayoutParams(params);
            tv.setGravity(Gravity.CENTER);
            tv.setTextSize(12);
            tv.setTextColor(Color.BLUE);
            viewHolder = new ViewHolder();
            viewHolder.tv = tv;
            convertView = tv;
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv.setText(chs.get(position).toUpperCase());

        return convertView;
    }
    class ViewHolder {
        TextView tv;
    }

}
